package homeworke.question18;

/**
 * Author：毕龙
 * Date: 2024/4/18 20:45
 */
public class Bank {
    public Account openAccount(long id,String password,int type){
        return type==0?new Account(id,password):type==1?
                new CreditAccount(id,password):new SavingAccount(id,password);
    }
    //存款
    public double deposit(Account a,double amount){
        return a.getBalance()+amount;
    }
    //取款
    public double withdraw(Account a,double amount){
        //表示余额大于取款额度
        if(a.getBalance() < amount){
            if(a instanceof CreditAccount  ){
                if(((CreditAccount) a).getCreditLine() > amount){
                    return ((CreditAccount) a).getCreditLine()-amount;
                }
                return ((CreditAccount) a).getCreditLine();
            }
            return a.getBalance();
        }
        return a.getBalance()-amount;
    }
}
